package com.accp.vehiclecare.biz.lscbiz;



import com.accp.vehiclecare.dao.lscdao.UserMapper;
import com.accp.vehiclecare.pojo.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserBiz {
    @Autowired
    private UserMapper dao;

    @Transactional(propagation = Propagation.REQUIRED)
    public int useraddone(User u){
        return dao.insert(u);
    }

    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<User> querall(String usertj){
        QueryWrapper qw= Wrappers.query();
        if(usertj!=null && usertj!="") {
            qw.eq("username", usertj);
            qw.or();
            qw.eq("userphone", usertj);
        }
        return  dao.selectList(qw);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public int removeone(Integer u){
        return dao.deleteById(u);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public int modif(User u){
        return dao.updateById(u);
    }

    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<User> querbyuno(String usno){
        QueryWrapper qw=Wrappers.query();
        qw.eq("userno",usno);
        return dao.selectList(qw);
    }

    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<User> quervip(Integer vipid,String zhi){
        QueryWrapper qw=Wrappers.query();
        qw.eq("isvip",vipid);
        qw.like("userphone",zhi);

        return dao.selectList(qw);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public  int modifvip(User user){
        return dao.updateById(user);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public  int modifye(User user){
        return dao.updateById(user);
    }
}
